package com.siruier.boss.ui.fragment.order

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.siruier.boss.R
import com.siruier.boss.bean.GiftWarehouseReceiveStateEnum
import com.siruier.boss.databinding.FragmentGiftWarehouseReceiveBinding
import com.siruier.boss.ui.base.BaseFragment
import com.siruier.boss.ui.helper.InjectBundle
import com.siruier.boss.ui.listener.OnTabSelectedListener
import com.siruier.boss.ui.utils.FragmentChangeManager

class GiftWarehouseReceiveFragment : BaseFragment<FragmentGiftWarehouseReceiveBinding>() {

    private val indexReceive: Int by InjectBundle { 0 }
    private var mFragmentChangeManager: FragmentChangeManager? = null

    override fun initView(rootView: View?, savedInstanceState: Bundle?) {
        val fragments = ArrayList<Fragment>()
        GiftWarehouseReceiveStateEnum.values().forEach { state ->
            vb.tabLayout.addTab(vb.tabLayout.newTab().setText(state.stateName))
            fragments.add(GiftWarehouseReceiveRvFragment.newInstance(state))
        }
        vb.tabLayout.addOnTabSelectedListener(OnTabSelectedListener {
            mFragmentChangeManager?.setFragments(it.position)
        })
        vb.tabLayout.getTabAt(indexReceive)?.select()
        mFragmentChangeManager = FragmentChangeManager(childFragmentManager, R.id.frameLayout, fragments, indexReceive)
    }
}